<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            height: 100px;
            width: 150px;
            background-color: pink;
        }
        .box1{
            margin: 0 auto;
        }
        .box2{
            position: relative;
            left: 50%;
            margin-left: -75px;
        }
        h3{
            text-align: center;
        }
    </style>
</head>
<body>
    <h3>第一个居中的盒子</h3>
    <div class="box1"></div>
    <h3>第二个居中的盒子</h3>
    <div class="box2"></div>
</body>
</html>